<template>
  <div class="app-container">
    <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" label-width="68px">
      <el-form-item label="单据编号" prop="code">
        <el-input
            v-model="queryParams.code"
            placeholder="请输入单据编号"
            clearable
            @keyup.enter.native="handleQuery"
            readonly
        />
      </el-form-item>
      <el-form-item label="源单据编号" prop="sourceCode" label-width="180px">
        <el-input
            v-model="queryParams.sourceCode"
            placeholder="请输入源单据编号"
            clearable
            @keyup.enter.native="handleQuery"
            readonly
        />
      </el-form-item>

      <el-form-item>
        <el-button type="primary" icon="el-icon-search" size="mini" @click="handleQuery">搜索</el-button>
<!--        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery" >重置</el-button>-->
      </el-form-item>
    </el-form>


    <el-table v-loading="loading" :data="gysbjList" @selection-change="handleSelectionChange">
      <el-table-column type="selection" width="55" align="center"/>
      <el-table-column label="主键Id" align="center" prop="id"/>
      <el-table-column label="单据编号" align="center" prop="code" width="200px" fixed/>
      <el-table-column label="源单据编号" align="center" prop="sourceCode" width="200px"/>
      <el-table-column label="供应商" align="center" prop="supplierName"/>

      <el-table-column label="创建人" align="center" prop="createBy"/>
      <el-table-column label="创建时间" align="center" prop="createTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.createTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="更新人" align="center" prop="updateBy"/>
      <el-table-column label="修改时间" align="center" prop="updateTime" width="180">
        <template slot-scope="scope">
          <span>{{ parseTime(scope.row.updateTime, '{y}-{m}-{d}') }}</span>
        </template>
      </el-table-column>
      <el-table-column label="备注" align="center" prop="remark"/>

    </el-table>

    <pagination
        v-show="total>0"
        :total="total"
        :page.sync="queryParams.pageNum"
        :limit.sync="queryParams.pageSize"
        @pagination="getList"
    />

  </div>
</template>

<script>
import {listGysbj} from "@/api/caigou/gysbj";
export default {
  name: "Gysbj",
  components: {},
  data() {
    return {
      // 被选中的供应报价数据
      selectGybjList:[],
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 供应商报价表格数据
      gysbjList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 10,
        code: null,
        sourceCode: null,
        docStage: null,
        approvalResult: null,
        isEffect: null,
        isClose: null,
        isCancel: null,
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        code: [
          {required: true, message: "单据编号不能为空", trigger: "blur"}
        ],
        supplierId: [
          {required: true, message: "供应商不能为空", trigger: "blur"}
        ],
        sourceCode: [
          {required: true, message: "请选择询价单", trigger: "blur"}
        ]
      }
    };
  },
  computed:{

  },
  created() {
    this.getList();
  },

  methods: {
    returnSelectGybjList(){
      return this.selectGybjList;
    },
    queryBySourceCode(sourceCode){
      this.queryParams.sourceCode = sourceCode;
      console.log('SelectGybj sourceCode',sourceCode)
      this.getList();
    },

    /** 查询供应商报价列表 */
    getList() {
      this.loading = true;
      listGysbj(this.queryParams).then(response => {
        this.gysbjList = response.rows;
        this.total = response.total;
        this.loading = false;
      });

    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: null,
        code: 'GYBJ-' + Date.now(),
        sourceCode: null,
        docStage: null,
        supplierId: null,
        approvalResult: null,
        isEffect: null,
        isClose: null,
        isCancel: null,
        createBy: null,
        createTime: null,
        updateBy: null,
        updateTime: null,
        remark: null,
        isDel: null
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.single = selection.length !== 1
      this.multiple = !selection.length
      console.log(selection);
      this.selectGybjList = selection;
    },


  }
};
</script>
